<?php
include_once('include/top.php');

if(isset($_POST['sub']))
{
    if($_GET['act']=='delete'&&$_POST['submit']!=''){
    for($i=0;$i<count($_POST['selectbox']);$i++)
    {
        $query = "delete from ".DBPREFIX."answer where uid=".$_POST['selectbox'][$i]." and exam_id=".$_POST['examid'];
        $result = $db->query($query);
    }
    if($result){
        fs_showmsg('删除成功!');
    }
    else{
        fs_showmsg('删除失败!');
    }
}
    ?><form action="?act=delete" method="post" onsubmit="return checkBoxSelect()">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr><td>
    <div class="submenu_t">
            
                <strong>考试成绩列表:</strong>
    </div>
    </td>
    </tr>
    <tr><td>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="question_list" id="tblist">
                            <thead>
                                    <tr>
                                            <th></th>
                                        <th>试卷名称</th>
                                        <th>答卷人</th>
                                        <th>成绩</th>
                                        <th>考试时间</th>                                      
                                </tr>
                            </thead>
                            <tbody>
                                    
                                            <?php 
                                            $member_sql = "select id from ".DBPREFIX."member where classid=".$_POST['classname'];
                                            $member_query  = $db->query($member_sql);
                                            $member_id =array();
                                            while($member_row = $db->fetch_array($member_query))      
                                            {
                                                $member_id[] = $member_row['id'];
                                            }
                                            $memberid = implode(',',$member_id);
                                            $memberid = ltrim($memberid,',');
                                            $query = "select sum(score) as score,uid,exam_id,exam_time  from ".DBPREFIX."answer  where exam_id=".$_POST['examtitle']." and uid in (".$memberid.") group by uid";
                                            $result = $db->query($query);
                                            while($row = $db->fetch_array($result))
                                            {   
                                               $get_username = get_realname_uid($row['uid']);
                                               $exam_name = get_exam_name($row['exam_id']);
                                               $recore_list = $row;
                                               
                                            ?>
                                            <tr>
                                                    <td><input type="checkbox" name="selectbox[]" value="<?php echo $recore_list['uid']; ?>" /></td>
                                                    <td><?php echo $exam_name; ?></td>                                                  
                                                    <td><?php echo $get_username; ?></td>
                                                    <td><?php echo $recore_list['score']; ?></td>
                                                    <td><?php echo date('Y-m-d',$row['exam_time']); ?></td>
                                            </tr>
                                            
                                    <?php
                                    }
                                    ?>
                            </tbody>
                    </table>
            </td></tr>
    <tr><td>
    <div class="submenu_b">
            <ul>
                <li><input type="button" name="selectall" id="allselect" value="全选"/></li>
		<li><input type="button" name="noneselect" id="noneselect" value="全不选"/></li>
        <li><input type="button" name="nonesselect" id="elseselect" value="反选"/><input type="hidden" name="examid" value="<?php echo $_POST['examtitle']?>"/><input type="hidden" name="sub" value="1"/></li>
		<li><input type="submit" name="submit"   value="删除"/></li>
            </ul>
    </div>
    </td>
    </tr>
</table>
</form>
<?php
}else{?>

<style type="text/css">
    #scoresearch td{
        height:55px;
    }
    .scoresearch h1{
        font-size:16px;
        font-weight:bold;
    }
    .scoresearch {
        padding-left:30px;
        border:1px solid #CCCCCC;
        padding-top:20px;
    }
</style><script type="text/javascript">
function CheckBanJi(){
    if(document.addform.dueid.value ==  "-1"){
       alert("请选择届!");
       return false;
    }
    if(document.addform.departid.value ==  "-1"){
       alert("请选择系!");
       return false;
    }
    if(document.addform.departid.value !=  "" &&document.addform.departid.value !=  "-1"){
           var majorid = document.addform.majorid.value;
           if(majorid =="-1"){
                   alert("请选择专业!");
                   return false;
           }
    }
    if(document.addform.classname.value ==  "-1"){
        alert("请选择班级!");
        document.addform.classname.focus();
        return  false;
    }
}
</script>
<div class="scoresearch" >
    <h1>成绩查询：</h1>
<form name="addform" action="" id="scoresearch" onsubmit="return CheckBanJi();" method="post">
    <table cellpadding="0" cellspacing="0" >
        <tr>
        <td>试题名称：</td>
        <td>
            <select name="examtitle" id="examtitle">
                <?php 
                $exam_sql = "select exam_id,exam_name from ".DBPREFIX."exam where exam_pubuid=".$teacher_id;
                $query  = $db->query($exam_sql);
                while($row = $db->fetch_array($query))
                {
                    ?>
                <option value="<?php echo $row['exam_id'] ?>"><?php echo $row['exam_name']?></option>
                <?php
                }?>
            </select>
        </td>
        </tr>
<!--         <tr>
            <td>所属班级：</td>
            <td>
                <select name="classname" id="classname">
                    <?php 
                    $class_sql = "select id,name from ".DBPREFIX."class";
                    $class_query  = $db->query($class_sql);
                    while($class_row = $db->fetch_array($class_query))
                    {
                        ?>
                    <option value="<?php echo $class_row['id'] ?>"><?php echo $class_row['name']?></option>
                    <?php
                    }?>
                </select>
            </td>
        </tr>-->
        
        <tr><td>届：</td> 
            <td>      
                        <select name="dueid" id="dueid" style="width:300px;">
                                <option value="-1">请选择届</option>
                                <?php
                                $sql="select* from nettteach_due where 1=1";
                                $result=mysql_query($sql);
                                //循环列出选项
                                        while($rows=mysql_fetch_array($result))
                                {?>
                                        <option value=<?php echo $rows['id']; ?>><?php echo $rows['name'];?></option>
                                <?php } ?>
                        </select>
            </td>
        </tr>
                    <tr><td>院系：</td> 
            <td>    
                        <select name="departid" id="departid" style="width:300px;">
                                <option value="-1">请选择系</option>
                        </select></td>
        </tr>
                    <tr><td>专业：</td> 
            <td>    <select name="majorid" id="majorid" style="width:300px;">
                                <option value="-1">请选择专业</option>
                        </select></td>
        </tr>
                    <tr><td>班级：</td> 
            <td>      <select name="classname" id="classname" style="width:300px;">
                                <option value="-1">请选择班级</option>
                        </select></td>
        </tr>
        
        <tr>
            <td colsspan="2"><input type="submit" name="sub" value="提交查询" /></td>
        </tr>
    </table>
</form>
</div><script type="text/javascript">
  function getOptionDEPARTMENT(){
  $.getJSON("option.php",{'departmentid':$("#dueid").val()},function(data){
    $("#departid").html("<option value='-1'>请选择系</option>");
    $("#majorid").html("<option value=''>请选择专业</option>");
    $("#classname").html("<option value=''>请选择班级</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#departid").append(option);
    });                
   }); 
 }
 function getOptionMAJOR(){
  $.getJSON("option.php",{'bval':$("#departid").val()},function(data){
    $("#majorid").empty();//每次选择前，清空小类的值。
    $("#classname").empty();
    $("#classname").html("<option value='-1'>请选择班级</option>");
    $("#majorid").html("<option value='-1'>请选择专业</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#majorid").append(option);
    });                
   }); 
 }
  function getOptionCLASS(){
  $.getJSON("option.php",{'classid':$("#majorid").val(),'dueid':$("#dueid").val()},function(data){
    $("#classname").empty();//每次选择前，清空小类的值。
    $("#classname").html("<option value='-1'>请选择班级</option>");
    $.each(data, function(index,array){
     var option="<option value='"+array['id']+"'>"+array['name']+"</option>"; 
     $("#classname").append(option);
    });                
   }); 
 }
 $(document).ready(function(){
    $("#dueid").change(function(){
        getOptionDEPARTMENT();
    });
    $("#departid").change(function(){
        getOptionMAJOR();
    });
    $("#majorid").change(function(){
        getOptionCLASS();
    });
 });
//    function checkform()
//    {
//        if($("#examtitle").val()=='')
//        {
//            alert('请选择一套试题作为查询单位');
//            return false;
//        }
//        elseif($("#classname").val()=='')
//        {
//            alert("请选择班级作为查询条件");
//            return false;
//        }
//        return true;
//    }
</script>
<?php
}?>